package com.unicloud.medical.sample.controller;

import com.unicloud.medical.oss.client.OSSClient;
import com.unicloud.medical.oss.common.ExtEndpoint;
import com.unicloud.medical.oss.common.constant.EndpointConstant;
import com.unicloud.medical.oss.common.model.BucketInfo;
import com.unicloud.medical.oss.common.model.DownloadObject;
import com.unicloud.medical.oss.common.model.ObjectInfo;
import com.unicloud.medical.oss.common.model.request.*;
import com.unisound.medical.common.annotation.Log;
import com.unisound.medical.common.model.dto.ResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test/api/sample")
public class SampleController implements ExtEndpoint {

    @Autowired
    private OSSClient ossClient;

    /**
     * 查看存储桶是否存在
     */
    @Log("查看存储桶是否存在")
    @PostMapping(EndpointConstant.BUCKET_EXIST)
    @Override
    public ResultDTO<Boolean> bucketExist(@RequestBody BucketExistRequest request) {
        return ossClient.bucketExist(request);
    }

    /**
     * 创建存储桶
     */
    @Log("创建存储桶")
    @PostMapping(EndpointConstant.CREATE_BUCKET)
    @Override
    public ResultDTO<Boolean> createBucket(@RequestBody CreateBucketRequest request) {
        return ossClient.createBucket(request);
    }

    /**
     * 创建默认权限存储桶
     */
    @Log("创建默认权限存储桶")
    @PostMapping(EndpointConstant.CREATE_DEFAULT_POLICY_BUCKET)
    @Override
    public ResultDTO<Boolean> createDefaultPolicyBucket(@RequestBody CreateBucketRequest request) {
        return ossClient.createDefaultPolicyBucket(request);
    }

    /**
     * 删除存储桶
     */
    @Log("删除存储桶")
    @PostMapping(EndpointConstant.REMOVE_BUCKET)
    @Override
    public ResultDTO<Boolean> removeBucket(@RequestBody DeleteBucketRequest request) {
        return ossClient.removeBucket(request);
    }

    /**
     * 获取全部存储桶
     */
    @Log("获取全部存储桶")
    @PostMapping(EndpointConstant.ALL_BUCKET)
    @Override
    public ResultDTO<List<BucketInfo>> getAllBuckets(@RequestBody CommonRequest request) {
        return ossClient.getAllBuckets(request);
    }

    /**
     * 获取当前存储桶所有文件
     */
    @Log("获取当前存储桶所有文件")
    @PostMapping(EndpointConstant.CURR_BUCKET_ALL_OBJECT)
    @Override
    public ResultDTO<List<ObjectInfo>> listAllObjectsCurrBucket(@RequestBody ListAllObjectsCurrBucketRequest request) {
        return ossClient.listAllObjectsCurrBucket(request);
    }

    /**
     * 获取当前存储桶当前文件夹所有文件
     */
    @Log("获取当前存储桶当前文件夹所有文件")
    @PostMapping(EndpointConstant.CURR_BUCKET_AND_FOLDER_ALL_OBJECT)
    @Override
    public ResultDTO<List<ObjectInfo>> listObjectsCurrBucketAndFolder(@RequestBody ListAllObjectsCurrBucketAndFolderRequest request) {
        return ossClient.listObjectsCurrBucketAndFolder(request);
    }

    /**
     * 批量文件上传
     */
    @Log("文件上传")
    @RequestMapping(value = EndpointConstant.UPLOAD_OBJECTS)
    public ResultDTO<List<String>> uploadObjects(UploadObjectsRequest request) {
        return ossClient.uploadObjects(request);
    }

    @Override
    public ResultDTO<List<String>> uploadObjects(InnerUploadObjectsRequest request) {
        return ossClient.uploadObjects(request);
    }

    @Log("文件上传")
    @RequestMapping(value = EndpointConstant.UPLOAD_OBJECT)
    public ResultDTO<String> uploadObject(UploadObjectRequest request) {
        return ossClient.uploadObject(request);
    }

    @Override
    public ResultDTO<String> uploadObject(InnerUploadObjectRequest request) {
        return ossClient.uploadObject(request);
    }

    /**
     * 本地文件上传
     */
    @Log("本地文件上传")
    @PostMapping(EndpointConstant.UPLOAD_LOCAL_OBJECT)
    @Override
    public ResultDTO<String> uploadLocalObject(@RequestBody UploadLocalObjectRequest request) {
        return ossClient.uploadLocalObject(request);
    }

    @Override
    public ResultDTO<List<String>> uploadLocalObjects(UploadLocalObjectsRequest request) {
        return null;
    }

    @Override
    public ResultDTO<DownloadObject> downloadObject(DownloadObjectRequest request) {
        return ossClient.downloadObject(request);
    }

    /**
     * 文件下载
     */
    @Log("文件下载")
    @RequestMapping(EndpointConstant.DOWNLOAD_OBJECT)
    @Override
    public ResponseEntity<byte[]> downloadObjectToBrowser(DownloadObjectRequest request) {
        return ossClient.downloadObjectToBrowser(request);
    }

    @Override
    public ResultDTO<DownloadObject> downloadObjects(DownloadObjectsRequest request) {
        return ossClient.downloadObjects(request);
    }

    /**
     * 下载文件夹下所有文件
     */
    @Log("下载文件夹下所有文件")
    @RequestMapping(EndpointConstant.CURR_FOLDER_DOWNLOAD_OBJECTS)
    @Override
    public ResponseEntity<byte[]> downloadObjectsToBrowser(DownloadObjectsRequest request) {
        return ossClient.downloadObjectsToBrowser(request);
    }

    /**
     * 根据url地址删除文件
     */
    @Log("根据url地址删除文件")
    @PostMapping(EndpointConstant.DELETE_OBJECT)
    @Override
    public ResultDTO removeObject(@RequestBody RemoveObjectRequest request) {
        return ossClient.removeObject(request);
    }

    /**
     * 根据url地址列表批量删除文件
     */
    @Log("根据url地址列表批量删除文件")
    @PostMapping(EndpointConstant.DELETE_OBJECTS)
    @Override
    public ResultDTO<List<String>> removeObjects(@RequestBody RemoveObjectsRequest request) {
        return ossClient.removeObjects(request);
    }

    /**
     * 删除当前桶当前文件夹所有文件
     */
    @Log("删除当前桶当前文件夹所有文件")
    @PostMapping(EndpointConstant.CURR_FOLDER_DELETE_OBJECTS)
    @Override
    public ResultDTO<List<String>> removeObjects(@RequestBody RemoveObjectsCurrBucketAndFolderRequest request) {
        return ossClient.removeObjects(request);
    }

    /**
     * 文件复制
     */
    @Log("文件复制")
    @PostMapping(EndpointConstant.COPY_OBJECT)
    @Override
    public ResultDTO<String> copyObject(@RequestBody CopyObjectRequest request) {
        return ossClient.copyObject(request);
    }

    /**
     * 已签名地址
     */
    @Log("已签名地址")
    @PostMapping(EndpointConstant.SIGNED_URL)
    @Override
    public ResultDTO<String> signedUrl(SignedUrlRequest request) {
        return ossClient.signedUrl(request);
    }

    /**
     * 批量已签名地址
     */
    @Log("批量已签名地址")
    @PostMapping(EndpointConstant.SIGNED_URLS)
    @Override
    public ResultDTO<List<String>> signedUrls(SignedUrlsRequest request) {
        return ossClient.signedUrls(request);
    }

}
